package com.tjyx.common.util.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * 数据库连接公共类
 * @author zhutianjie
 *
 */
public class DBConnector {

	public static Connection conn = null;
	/**
	 * 数据连接
	 * @return
	 */
	public static Connection getConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/eps888?characterEncoding=UTF-8", "root", "123456");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("数据库连接异常,找不到驱动类!" + e.getMessage());
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("数据库连接异常,找不到指定URL!" + e.getMessage());
		}
		return conn;
	}
	
	/**
	 * 数据库资源释放
	 * @param conn
	 * @param ps
	 * @param rs
	 */
	public static void clear(Connection conn, PreparedStatement ps, ResultSet rs) {
		try {
			if(conn != null) {
				conn.close();
			}
			if(ps != null) {
				ps.close();
			}
			if(rs != null) {
				rs.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
}
